//
//  SoundSettingViewController.m
//  SIPphone
//
//  Created by wrt on 13-11-13.
//  Copyright (c) 2013年 wrtsoft. All rights reserved.
//

#import "SoundSettingViewController.h"
#import "SoundCodeSettingViewController.h"

@interface SoundSettingViewController ()

@end

@implementation SoundSettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = NSLocalizedString(@"audio Settings", @"音频配置 Audio Settings");
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *isOpenSound = [[NSString alloc] init];
    isOpenSound = [defaults objectForKey:@"SAVEISOPENSOUND"];
    if (isOpenSound.length > 0)
    {
        if ([isOpenSound isEqualToString:@"YES"])
        {
            [self.soundSwitch setOn:YES];
        }
        else if ([isOpenSound isEqualToString:@"NO"])
        {
            [self.soundSwitch setOn:NO];
        }
    }
}

- (IBAction)openViewSwitch:(id)sender
{
    UISwitch *switchControl = (UISwitch *)sender;
    SIPInterface *interface = [SIPInterface shareSIPInterface];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    BOOL isOpenSound = switchControl.on;
    if (isOpenSound == YES)
    {
        [interface isOpenSound:YES];
        [defaults setObject:@"YES" forKey:@"SAVEISOPENSOUND"];
    }
    else
    {
        [interface isOpenSound:NO];
        [defaults setObject:@"NO" forKey:@"SAVEISOPENSOUND"];
    }
    [defaults synchronize];
}
- (IBAction)soundTest:(id)sender
{
    SIPInterface *interface = [SIPInterface shareSIPInterface];
    [interface testSound];
}
- (IBAction)audioCodeOnButton:(id)sender
{
    SoundCodeSettingViewController *soundCodeSettingVC = [[SoundCodeSettingViewController alloc] init];
    [self.navigationController pushViewController:soundCodeSettingVC animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
